package demo5;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-08-11
 * Time: 15:57
 */
public class TestDemo1 {

    public static AtomicInteger atomicInteger = new AtomicInteger();

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
            for(int i =0;i<5000;++i){
                atomicInteger.getAndIncrement();
            }
        });
        Thread t2 = new Thread(()->{
            for(int i =0;i<5000;++i){
                atomicInteger.getAndIncrement();
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(atomicInteger.get());
    }

}
